package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcCzj;
import com.ruoyi.wgjlcData.domain.vo.TestOneData;
import com.ruoyi.wgjlcData.mapper.DataWgjlcCzjMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcCzjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车-最大操纵角测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcCzjServiceImpl implements IDataWgjlcCzjService
{
    @Autowired
    private DataWgjlcCzjMapper dataWgjlcCzjMapper;

    /**
     * 查询无轨胶轮车-最大操纵角测试项
     * 
     * @param czjId 无轨胶轮车-最大操纵角测试项主键
     * @return 无轨胶轮车-最大操纵角测试项
     */
    @Override
    public DataWgjlcCzj selectDataWgjlcCzjByCzjId(Long czjId)
    {
        return dataWgjlcCzjMapper.selectDataWgjlcCzjByCzjId(czjId);
    }

    /**
     * 查询无轨胶轮车-最大操纵角测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-最大操纵角测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcCzj>> selectDataWgjlcChwqdByDataTaskId(Long dataTaskId) {
        List<DataWgjlcCzj> dataWgjlcCzjEntities = dataWgjlcCzjMapper.selectDataWgjlcCzjByDataTaskId(dataTaskId);
        if (dataWgjlcCzjEntities.size() != 0) {
            dataWgjlcCzjEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestOneDataList(JSON.parseArray(item.getDataList(), TestOneData.class));
                    item.setListSize(item.getTestOneDataList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcCzjEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcCzjByDataTaskId(Long dataTaskId) {
        return dataWgjlcCzjMapper.updateDataWgjlcCzjByDataTaskId(dataTaskId);
    }

    /**
     * 查询无轨胶轮车-最大操纵角测试项列表
     * 
     * @param dataWgjlcCzj 无轨胶轮车-最大操纵角测试项
     * @return 无轨胶轮车-最大操纵角测试项
     */
    @Override
    public List<DataWgjlcCzj> selectDataWgjlcCzjList(DataWgjlcCzj dataWgjlcCzj)
    {
        return dataWgjlcCzjMapper.selectDataWgjlcCzjList(dataWgjlcCzj);
    }

    /**
     * 新增无轨胶轮车-最大操纵角测试项
     * 
     * @param dataWgjlcCzj 无轨胶轮车-最大操纵角测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcCzj(DataWgjlcCzj dataWgjlcCzj)
    {
        dataWgjlcCzj.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcCzjMapper.insertDataWgjlcCzj(dataWgjlcCzj);
    }

    /**
     * 批量新增无轨胶轮车-最大操纵角测试项
     *
     * @param dataWgjlcCzj 无轨胶轮车-最大操纵角测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcCzj(List<DataWgjlcCzj> dataWgjlcCzj) {
        return dataWgjlcCzjMapper.batchDataWgjlcCzj(dataWgjlcCzj);
    }

    /**
     * 修改无轨胶轮车-最大操纵角测试项
     * 
     * @param dataWgjlcCzj 无轨胶轮车-最大操纵角测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcCzj(DataWgjlcCzj dataWgjlcCzj)
    {
        dataWgjlcCzj.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcCzj.getTestOneDataList().isEmpty()) {
            dataWgjlcCzj.setDataList(JSON.toJSONString(dataWgjlcCzj.getTestOneDataList()));
        }
        return dataWgjlcCzjMapper.updateDataWgjlcCzj(dataWgjlcCzj);
    }

    /**
     * 批量删除无轨胶轮车-最大操纵角测试项
     * 
     * @param czjIds 需要删除的无轨胶轮车-最大操纵角测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcCzjByCzjIds(Long[] czjIds)
    {
        return dataWgjlcCzjMapper.deleteDataWgjlcCzjByCzjIds(czjIds);
    }

    /**
     * 删除无轨胶轮车-最大操纵角测试项信息
     * 
     * @param czjId 无轨胶轮车-最大操纵角测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcCzjByCzjId(Long czjId)
    {
        return dataWgjlcCzjMapper.deleteDataWgjlcCzjByCzjId(czjId);
    }
}
